package com.edmond.jyframe.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.edmond.jyframe.R;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

/**
 * Created by edmond on 17-4-29.
 */

public class WebView extends AppCompatActivity {
    android.webkit.WebView webView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web);

        webView = (android.webkit.WebView) findViewById(R.id.web);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.setVerticalScrollBarEnabled(true);
        webView.loadDataWithBaseURL(null,getNewContent("<html><body>dfjksdjfklsdfj施展<img src=\"http://img05.tooopen.com/images/20150202/sy_80219211654.jpg\"/><img src=\"http://img05.tooopen.com/images/20150202/sy_80219211654.jpg\"/><img src=\"http://img05.tooopen.com/images/20150202/sy_80219211654.jpg\"/><img src=\"http://img05.tooopen.com/images/20150202/sy_80219211654.jpg\"/><img src=\"http://img05.tooopen.com/images/20150202/sy_80219211654.jpg\"/><img src=\"http://img05.tooopen.com/images/20150202/sy_80219211654.jpg\"/><img src=\"http://img05.tooopen.com/images/20150202/sy_80219211654.jpg\"/><img src=\"http://img05.tooopen.com/images/20150202/sy_80219211654.jpg\"/><img src=\"http://img05.tooopen.com/images/20150202/sy_80219211654.jpg\"/><img src=\"http://img05.tooopen.com/images/20150202/sy_80219211654.jpg\"/></body></html>"),"text/html","charset=UTF-8", null);

    }

    private String getNewContent(String htmltext){

        Document doc= Jsoup.parse(htmltext);
        Elements elements=doc.getElementsByTag("img");
        for (Element element : elements) {
            element.attr("width","100%").attr("height","auto");
        }

        Log.d("VACK", doc.toString());
        return doc.toString();
    }
}
